home *** CD-ROM | disk | FTP | other *** search
Wrap
RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) NNNNaaaammmmeeee RWTPtrHashMultiMap<K,T,H,EQ> - Rogue Wave library class SSSSyyyynnnnooooppppssssiiiissss #include <rw/tphmmap.h> RWTPtrHashMultiMap<K,T,H,EQ> m; SSSSttttaaaannnnddddaaaarrrrdddd CCCC++++++++ LLLLiiiibbbbrrrraaaarrrryyyy DDDDeeeeppppeeeennnnddddeeeennnntttt!!!! RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp requires the Standard C++ Library. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn This class maintains a pointer-based collection of associatoins of type ppppaaaaiiiirrrr<<<<KKKK**** ccccoooonnnnsssstttt,,,, TTTT****>>>>. These pairs are stored according to a hash object of type HHHH. HHHH must provide a hash function on elements of type KKKK via a public member unsigned long operator()(const K& x) Equivalent keys within the collection will be grouped together based on an equality object of type EEEEQQQQ. EEEEQQQQ must ensure this grouping via public member bool operator()(const K& x, const K& y) which should return ttttrrrruuuueeee if xxxx and yyyy are equivalent. RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,HHHH,,,,EEEEQQQQ>>>> may contain multiple keys that compare equal to each other. (RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,HHHH,,,,EEEEQQQQ>>>> will not accept a key that compares equal to any key already in the collection.) Equality is based on the comparison object and not on the ======== operator. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee PPPPaaaaggggeeee 1111 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) Isomorphic EEEExxxxaaaammmmpppplllleeeessss // // tphmap.cpp // #include<rw/tphmmap.h> #include<rw/cstring.h> #include<iostream.h> struct silly_hash{ unsigned long operator()(RWCString x) const { return x.length() * (long)x[0]; } }; int main(){ RWCString snd = "Second"; RWTPtrHashMultiMap<RWCString,int,silly_hash,equal_to<RWCString> > contest; contest.insert(new RWCString("First"), new int(7)); contest.insert(&snd, new int(3)); contest.insert(&snd, new int(6)); // duplicate key OK contest.insert(new RWCString("Third"), new int(2)); cout << "There were " << contest.occurrencesOf(&snd) << " second place winners." << endl; return 0; } Program Output: There were 2 second place winners. RRRReeeellllaaaatttteeeedddd CCCCllllaaaasssssssseeeessss Class RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,HHHH,,,,EEEEQQQQ>>>> offers the same interface to a pointer- based collection that will not accept multiple keys that compare equal to each other. rrrrwwww____hhhhaaaasssshhhhmmmmuuuullllttttiiiimmmmaaaapppp<<<<<<<<KKKK****,,,,TTTT****>>>>,rrrrwwww____ddddeeeerrrreeeeffff____hhhhaaaasssshhhh<<<<HHHH,,,,KKKK>>>>,,,,rrrrwwww____ddddeeeerrrreeeeffff____ccccoooommmmppppaaaarrrreeee<<<<EEEEQQQQ,,,,KKKK>>>> >>>> is the C++-standard style collection that serves as the underlying implementation for this collection. PPPPuuuubbbblllliiiicccc TTTTyyyyppppeeeeddddeeeeffffssss typedef rw_deref_hash<H,K> container_hash; typedef rw_deref_compare<EQ,K> container_eq; typedef rw_hashmultimap<K*,T*,container_hash,container_eq> container_type; typedef container_type::size_type size_type; typedef container_type::difference_type difference_type; typedef container_type::iterator iterator; typedef container_type::const_iterator const_iterator; typedef pair <K* const, T*> value_type; typedef pair <K* const, T*>& reference; typedef const pair <K* const, T*>& const_reference; typedef K* value_type_key; PPPPaaaaggggeeee 2222 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) typedef T* value_type_data; typedef K*& reference_key; typedef T*& reference_data; typedef const K*const& const_reference_key; typedef const T*const& const_reference_data; PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,HHHH,,,,EEEEQQQQ>>>>(); Constructs an empty map. RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,HHHH,,,,EEEEQQQQ>>>>(const container_type& m); Constructs a multi-map by doing an element by element copy from the C++ Standard Library style hashed multi-map, mmmm. RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,HHHH,,,,EEEEQQQQ>>>> (const RWTPtrHashMultiMap<K,T,H,EQ>& rwm); Copy constructor. RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,HHHH,,,,EEEEQQQQ>>>> (value_type* first, value_type* last); Constructs a map by copying elements from the array of ppppaaaaiiiirrrrs pointed to by ffffiiiirrrrsssstttt, up to, but not including, the pair pointed to by llllaaaasssstttt. RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,HHHH,,,,EEEEQQQQ>>>> (const H& h, size_type sz = RWDEFAULT_CAPACITY); This TTTToooooooollllssss....hhhh++++++++ 6.x style constructor creates an empty hashed multi-map which uses the hash object hhhh and has an initial capacity of sssszzzz. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr OOOOppppeeeerrrraaaattttoooorrrrssss RWTPtrHashMultiMap<K,T,H,EQ>& ooooppppeeeerrrraaaattttoooorrrr====(const container_type&jjj m); RWTPtrHashMultiMap<K,T,H,EQ>& ooooppppeeeerrrraaaattttoooorrrr====(const RWTPtrHashMultiMap<K,T,H,EQ>& m); Destroys all associations in self and replaces them by copying all associations from mmmm. PPPPaaaaggggeeee 3333 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) bool ooooppppeeeerrrraaaattttoooorrrr========(const RWTPtrHashMultiMap<K,T,H,EQ>& m); Returns ttttrrrruuuueeee if self compares equal to mmmm, otherwise returns ffffaaaallllsssseeee. Two collections are equal if both have the same number of entries, and iterating through both collections produces, in turn, individual keys that compare equal to each other. Keys are dereferenced before being compared. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss void aaaappppppppllllyyyy(void (*fn)(const K*, T*&,void*),void* d); void aaaappppppppllllyyyy(void (*fn)(const K*, const T*, void*), void* d) const; Applies the user-defined function pointed to by ffffnnnn to every association in the collection. self function must have one of the prototypes: void yourfun(const K* key, T*& a, void* d); void yourfun(const K* key, const T* a, void* d); Client data may be passed through parameter dddd. void aaaappppppppllllyyyyTTTTooooKKKKeeeeyyyyAAAAnnnnddddVVVVaaaalllluuuueeee(void (*fn)(const K*, T*&,void*),void* d); void aaaappppppppllllyyyyTTTTooooKKKKeeeeyyyyAAAAnnnnddddVVVVaaaalllluuuueeee (void (*fn)(const K*, const T*, void*), void* d) const; This is a deprecated version of the aaaappppppppllllyyyy member above. It behaves exactly the same as aaaappppppppllllyyyy. iterator bbbbeeeeggggiiiinnnn(); const_iterator bbbbeeeeggggiiiinnnn() const; Returns an iterator positioned at the first pair in self. size_type ccccaaaappppaaaacccciiiittttyyyy() const; Returns the number of buckets (slots) available in the underlying hash PPPPaaaaggggeeee 4444 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) representation. See rrrreeeessssiiiizzzzeeee below. void cccclllleeeeaaaarrrr(); Clears the collection by removing all items from self. void cccclllleeeeaaaarrrrAAAAnnnnddddDDDDeeeessssttttrrrrooooyyyy(); Removes all associations from the collection and uses ooooppppeeeerrrraaaattttoooorrrr ddddeeeelllleeeetttteeee to destroy the objects pointed to by the keys and their associated items. Do not use self method if multiple pointers to the same keys or items are stored. bool ccccoooonnnnttttaaaaiiiinnnnssss(const K* key) const; Returns ttttrrrruuuueeee if there exists a key jjjj in self that compares equal to ****kkkkeeeeyyyy, otherwise returns ffffaaaallllsssseeee. bool ccccoooonnnnttttaaaaiiiinnnnssss(bool (*fn)(value_type,void*),void* d) const; Returns ttttrrrruuuueeee if there exists an association a in self such that the expression ((((((((****ffffnnnn))))((((aaaa,,,,dddd)))))))) is ttttrrrruuuueeee, otherwise returns ffffaaaallllsssseeee. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(value_type* a, void* d); Client data may be passed through parameter dddd. iterator eeeennnndddd(); const_iterator eeeennnndddd() const; Returns an iterator positioned "just past" the last association in self. size_type eeeennnnttttrrrriiiieeeessss() const; PPPPaaaaggggeeee 5555 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) Returns the number of associations in self. float ffffiiiillllllllRRRRaaaattttiiiioooo() const; Returns the ratio eeeennnnttttrrrriiiieeeessss(((())))/ccccaaaappppaaaacccciiiittttyyyy(((()))). const K* ffffiiiinnnndddd(const K* key) const; If there exists a key jjjj in self that compares equal to ****kkkkeeeeyyyy, then jjjj is returned. Otherwise, returns rrrrwwwwnnnniiiillll. value_type ffffiiiinnnndddd(bool (*fn)(value_type,void*), void* d) const; If there exists an association aaaa in self such that the expression ((((((((****ffffnnnn))))((((aaaa,,,,dddd)))))))) is ttttrrrruuuueeee, then returns aaaa. Otherwise, returns ppppaaaaiiiirrrr<<<<rrrrwwwwnnnniiiillll,,,,rrrrwwwwnnnniiiillll>>>>. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(value_type a, void* d); Client data may be passed through parameter dddd. T* ffffiiiinnnnddddVVVVaaaalllluuuueeee(const K* key); const T* ffffiiiinnnnddddVVVVaaaalllluuuueeee(const K* key) const; If there exists a key jjjj in self that compares equal to ****kkkkeeeeyyyy, returns the item associated with jjjj. Otherwise, returns rrrrwwwwnnnniiiillll. const K* ffffiiiinnnnddddKKKKeeeeyyyyAAAAnnnnddddVVVVaaaalllluuuueeee(const K* key, T*& tr); const K* ffffiiiinnnnddddKKKKeeeeyyyyAAAAnnnnddddVVVVaaaalllluuuueeee(const K* key, const T*& tr) const; If there exists a key jjjj in self that compares equal to ****kkkkeeeeyyyy, assigns the item associated with jjjj to trrrr,,,, and returns jjjj. Otherwise, returns rrrrwwwwnnnniiiillll and leaves the value of ttttrrrr unchanged. PPPPaaaaggggeeee 6666 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) bool iiiinnnnsssseeeerrrrtttt(K* key,T* a); Adds kkkkeeeeyyyy with associated item aaaa to the collection. Returns ttttrrrruuuueeee. bool iiiinnnnsssseeeerrrrttttKKKKeeeeyyyyAAAAnnnnddddVVVVaaaalllluuuueeee(K* key,T* a); This is a deprecated version of the iiiinnnnsssseeeerrrrtttt member above. It behaves exactly the same as iiiinnnnsssseeeerrrrtttt. bool iiiissssEEEEmmmmppppttttyyyy() const; Returns ttttrrrruuuueeee if there are no items in the collection, ffffaaaallllsssseeee otherwise. size_type ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(const K* key) const; Returns the number of keys jjjj in self that compare equal to ****kkkkeeeeyyyy. size_type ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff (bool(*fn)(value_type,void*),void* d)const; Returns the number of associations aaaa in self such that the expression((((((((****ffffnnnn))))((((aaaa,,,,dddd)))))))) is ttttrrrruuuueeee. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(value_type a, void* d); Client data may be passed through parameter dddd. K* rrrreeeemmmmoooovvvveeee(const K* key); Removes the first association with key jjjj in self that compares equal to ****kkkkeeeeyyyy. Returns rrrrwwwwnnnniiiillll if there is no such association. K* rrrreeeemmmmoooovvvveeee(bool (*fn)(value_type,void*), void* d); PPPPaaaaggggeeee 7777 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) Removes the first association aaaa in self such that the expression ((((((((****ffffnnnn))))((((aaaa,,,,dddd)))))))) is ttttrrrruuuueeee and returns its key. Returns rrrrwwwwnnnniiiillll if there is no such association. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(value_type a, void* d); Client data may be passed through parameter dddd. size_type rrrreeeemmmmoooovvvveeeeAAAAllllllll(const K* key); Removes all associations with key jjjj in self that compare equal to ****kkkkeeeeyyyy. Returns the number of associations removed. size_type rrrreeeemmmmoooovvvveeeeAAAAllllllll(bool (*fn)(value_type,void*), void* d); Removes all associations aaaa in self such that the expression ((((((((****ffffnnnn))))((((aaaa,,,,dddd))))))))is ttttrrrruuuueeee. Returns the number removed. ffffnnnn points to a user- defined tester function which must have prototype: bool yourTester(value_type a, void* d); Client data may be passed through parameter dddd. void rrrreeeessssiiiizzzzeeee(size_type sz); Changes the capacity of self by creating a new hashed multi-map with a capacity of sssszzzz . rrrreeeessssiiiizzzzeeee then copies every element of sssseeeellllffff into the new container and finally swaps the internal representation of the new container with sssseeeellllffff. container_type& ssssttttdddd(); const container_type& ssssttttdddd() const; Returns a reference to the underlying C++-standard collection that serves PPPPaaaaggggeeee 8888 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) as the implementation for self. RRRReeeellllaaaatttteeeedddd GGGGlllloooobbbbaaaallll OOOOppppeeeerrrraaaattttoooorrrrssss RWvostream& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWvostream& strm, const RWTPtrHashMultiMap<K,T,H,EQ>& coll); RWFile& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWFile& strm, const RWTPtrHashMultiMap<K,T,H,EQ>& coll); Saves the collection ccccoooollllllll onto the output stream ssssttttrrrrmmmm, or a reference to it if it has already been saved. RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTPtrHashMultiMap<K,T,H,EQ>& coll); RWFile& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTPtrHashMultiMap<K,T,H,EQ>& coll); Restores the contents of the collection ccccoooollllllll from the input stream ssssttttrrrrmmmm. RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTPtrHashMultiMap<K,T,H,EQ>*& p); RWFile& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTPtrHashMultiMap<K,T,H,EQ>*& p); Looks at the next object on the input stream ssssttttrrrrmmmm and either creates a new collection off the heap and sets pppp to point to it, or sets pppp to point to a previously read instance. If a collection is created off the heap, then you are responsible for deleting it. PPPPaaaaggggeeee 9999